package com.ll.xiaonew.commons.core.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;

/**
 * @author new
 * @date 2022/12/2 19:29
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R extends HashMap {
    private Integer code;
    private String messg;
    private Object data;

    public R put(String key, Object value) {
        super.put(key,value);
        return this;
    }

    public static R success(){
        R r = new R();
        r.put("code",200);//成功
        return  r;
    }

    public static R erro(){
        R r = new R();
        r.put("code",500);//失败
        return r;
    }

    public static R erro(String msg){
        R r = new R();
        r.put("msg",msg);//失败错误信息
        return r;
    }

    public static R success(Object data){
        R r = new R();
        r.put("data",data);//成功带入数据
        return r;
    }

    public static R write(Boolean flag){
        if (flag) {
           return R.success();
        }
        return R.erro("参数错误");
    }

}
